import Loading from '@jiess/http/loading';
import { message } from 'antd';
export function responseSuccessFunc({ responseText, config }) {
  Loading.response(config.mainURL, config.method);
  let response = JSON.parse(responseText);
  if (response.code === 200) {
    return response.data;
  } else {
    errorHandler(response);
    return Promise.reject(response);
  }

  function errorHandler(res) {
    if (res.code === '401') {
      // token校验失败
    } else {
      message.error(res.msg);
    }
  }
}

export function responseErrorFunc({ responseText, config }) {
  Loading.response(config.mainURL, config.method);
  message.error(responseText);
}

export function requestFunc(config) {
  Loading.request(config.mainURL, config.method);
  return config;
}
